package com.nf.action;


import com.nf.entity.Student2;
import com.nf.entity.TestMoney;
import com.nf.service.TestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.sql.SQLException;
import java.util.List;

@Controller
public class Test1 {

    @Autowired
    private TestService testService;

    @RequestMapping("/aa")
    public String c1(Model model){
        String dateStr = testService.getDate();
        model.addAttribute("dateStr",dateStr);
        System.out.println(dateStr);
        return "a1";
    }

    @RequestMapping("/aa2")
    public String c2(Model model) throws SQLException {
        String meiyuan = testService.getString();
        model.addAttribute("meiyuan",meiyuan);
        System.out.println(meiyuan);
        return "a2";
    }

    @Autowired
    private TestMoney testMoney;

    @RequestMapping("/aa3")
    public String c3(){
        System.out.println(testMoney);
        return "a3";
    }

    @Autowired
    private List<TestMoney> testMoneyList;

    @RequestMapping("/aa4")
    public String c4(){
        System.out.println(testMoneyList);
        return "a3";
    }

    @RequestMapping("/aa5")
    public String c5(Model model,int discount){
        String carDiscount = testService.getCarDiscount(discount);
        model.addAttribute("carDiscount",carDiscount);
        System.out.println(carDiscount);
        return "a5";
    }

    @RequestMapping("/Show")
    public String cc6(){
        return "json1";
    }

    @ResponseBody//提供关于，知道是json
    @RequestMapping("/jsonShow")
    public List<Student2> c6(){
        List<Student2> student2List = testService.getListStudent2();
        System.out.println(student2List);
        return student2List;
    }

    @RequestMapping("/detele")
    public String c7(int id){
        boolean ok = testService.getDeteleStudent2(id);
        if(ok==true){
            return "json1";
        }else {
            return "error";
        }
    }

    @RequestMapping("/jdbc")
    public String c8(){
        Student2 student2 = testService.getJDBCStudent2();
        System.out.println(student2.getId());
        return "a7";
    }

}
